<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <input type="text" class="user">
    <br>
    <input type="password" class="pwd">
    <br>
    <button>登录</button>

    <script>

        const oBtn = document.querySelector('button') ;
        const oUser = document.querySelector('.user') ;
        const oPwd = document.querySelector('.pwd') ;

        oBtn.onclick = function() {
            
            const username = oUser.value ;
            const userpwd = oPwd.value ;
            // 用户名和密码的验证


            const xhr = new XMLHttpRequest() ;
            // get请求在问号后面携带参数
            xhr.open('get' , `../php/04接收前端数据.php?username=${username}&userpwd=${userpwd}` , true) ;
            xhr.send() ;
            xhr.onreadystatechange = function() {
                if(xhr.readyState === 4 && xhr.status === 200) {
                    let data = xhr.responseText ;
                    data = JSON.parse(data) ;
                    console.log(data);
                }
            }



        }

    </script>
    
</body>
</html>